package me.zk.practice1.s;

/**
 * @author zhangkai
 * @date 2023/7/13 11:45
 */
public class LS_Offer_18 {
    public ListNode deleteNode(ListNode head, int val) {
        if (head == null) {
            return null;
        }
       if (head.val == val) {
           return head.next;
       }
       ListNode pre = head;
       ListNode current = head.next;
       while (current!= null) {
           if (current.val== val) {
               pre.next = current.next;
               break;
           }
           pre = current;
           current = current.next;

       }
       return head;
    }

}
